<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<tpl> $NCharset </tpl>" />
<title><tpl> $langCShopNCSystem </tpl></title>
<tpl>include file ='sys_head_config.html'</tpl>
<script language="javascript" src="../js/show_dialog.js" type="text/javascript"></script>
</head>
<body>
<div class="tabbar">
  <ul class="tab_btns" id="COPYYH2">
    <li class="current"><a href="attribute.manage.php?action=list"><span><tpl> $langAMProductManage </tpl></span></a></li>
  </ul>
	<div class="tab_notes" id="copyyh0">
		<ul class="notesbg block"><span><h4><tpl> $langAMProductClassManage </tpl></h4></span></ul>
	</div>
	<!-- 显示提示信息 -->
	<div id="message"></div>
	<!-- 显示提示信息end -->
</div>
<div id="product-help" class="admincp_form" style="top:88px;">
<div id="result_content" style="padding-left:10px;">
	<form name="form_attribute_manage"><tpl> $slPCategory </tpl></form><br /><tpl> $langAMProductClassClassManage </tpl>
	<!-- 商品属性 -->
	<div id="attribute_manage_type" style="display:none; width:100%" class="zhl_shuxing">
		<form name="form_Attribute" id="form_Attribute" method="post" action="attribute.manage.php?action=add">
		
		<p style="color: #29a1d9; font-weight:bold; padding-left:100px; padding-top:20px;"><tpl> $langAMAddClassNew </tpl></p>
		<div id="show_message"></div>
		<div id="errormessage"></div>
		<ul>
			<li style="color: #29a1d9; font-weight:bold;"><b style="padding-right:10px;"><tpl> $langAMName </tpl></b><input name="txtAname" id="txtAname" type="text" size="50" class="txtinput" />　*<label style="display:none;" for="txtAname" class="wrong" metaDone="true" generated="true"></label>
</li>
			<li style="color: #29a1d9; font-weight:bold;"><b style="padding-right:10px;"><tpl> $langAMType </tpl></b><input  type="radio" name="txtAtype" value="0" checked="checked"><tpl> $langAMBarelyRadio </tpl>  <input type="radio" name="txtAtype" value="1"><tpl> $langAMCanMoreSelect </tpl>  *</li>
			<li style="color: #29a1d9; font-weight:bold;"><b style="padding-right:10px;"><tpl> $langAMCompositor </tpl></b><input name="txtAorder" class="txtinput" id="txtAorder" type="text" value="0" size="50">　*<label style="display:none" for="txtAorder" class="wrong" metaDone="true" generated="true"></label>
<label for='txtAorder'> </label> </li>
			<li style="color: #29a1d9; font-weight:bold;"><b style="padding-right:10px;"><tpl> $langAMExplain </tpl></b><input name="txtAinfo" class="txtinput" type="text" value="" size="50"><input type="hidden" name="txtApcid" id="txtApcid" value="" /></li>
			<li style=" margin-top:10px; padding-left:100px; "><span class="btn_left"><input name="submit" type="submit" class="btn_submit" value=" <tpl> $langbtnASubmit </tpl> "></span></li>
		</ul>
		<div style="clear:both"></div>
		</form>
	</div>
	<div id="show_list">
	</div>

	<pre id="contentDIV" style="display:none"></pre>
	<!-- 复制属性，包括单一属性和某一类别属性 -->
	<pre id="copyDIV" style="display:none;"></pre>
</div>
</div>
<!-- 帮助菜单 -->
<tpl> include file='sys_right_help.html' </tpl>
<!-- 帮助菜单END -->
</body>
</html>
<script language="javascript">
var ShowContentDiv = "show_list";
var pcid;
var question;
var content;
$(document).ready(function() {
	hideLoading();
	
	$().ajaxStop($.unblockUI);
	
	<tpl> if $list_class_error != '' </tpl>
	//输出后台程序错误信息
	showMessage(<tpl> $list_class_error </tpl>,0);
	<tpl> /if </tpl>
	
	var options_list = {
		success:       showResponse,  // 提交成功后执行的方法
		type:      'get'       // 'get' or 'post', 提交类型，重写form表单的method值
	};

	//选择下拉框触发的事件
	$("#slPCId").change(function(){
		pcid = this.options[this.selectedIndex].value;
		if (pcid > 0){
			//如果选种某个分类则显示添加部分，并且显示其分类下的属性列表
			$("#attribute_manage_type").show();
			//alert(pcid);
			$("#txtApcid").attr("value",pcid);
			//显示属性列表
			getAttribute('attribute.manage.php?action=ajax_show&pcid='+this.options[this.selectedIndex].value);
		}else{
			//如果没有选中某个类别则隐藏添加部分
			$("#attribute_manage_type").hide();
			$("#show_list").text("");
		}
	});
	//对添加表单做的验证定义
	$("#form_Attribute").validate({
		errorClass: "wrong",
		rules: {
			txtAname: {required:true},
			txtAorder: {required:true}
		},
		messages: {
			txtAname: {required: "<tpl> $langAMFillInName </tpl>"},
			txtAorder: {required: "<tpl> $langAMFillInCompositor </tpl>"}
		},
		submitHandler: function() {
			//提交表单操作
			$('#form_Attribute').ajaxSubmit({ beforeSubmit:function(){showLoading(showSaveText);},success: addAttr, type:'post', dataType:'json'});
		}
	});	
});
//定义提交添加表单后的操作
function addAttr(responseText,statusText){
	var msg = "<tpl> $langAMSaveOk </tpl>";
	showMessage(msg);
	$("#txtApcid").attr("value",pcid);
	//alert(responseText.message);
	getAttribute('attribute.manage.php?action=ajax_show&pcid=' + pcid,1);
	//alert(pcid);
}
//显示属性列表
function getAttribute(address,type){
	$.ajax({
		url: address,
		// ifModified:true,   使用这个属性firefox会有问题，无法成功响应
		beforeSubmit:  showLoading(showText),
		success: function(msg){
			$("#" + ShowContentDiv).html(msg);
			//$("#" + ShowContentDiv).css("display","block");<br>
			hideLoading();
			question = $('#question')[0];
			//$("#question").css("display","block");
			content = $('#contentDIV')[0];
			//修改属性
			$('form','#attribute_manage_type2').submit(function(){
				//alert(this.name);
				myform = this.name;
				$("#" + myform).validate({
					//debug :true,
					errorClass: "wrong",
					rules: {
						txtAname: {required:true},
						txtAorder: {required:true}
					},
					messages: {
						txtAname: {required: "<tpl> $langAMFillInName </tpl>"},
						txtAorder: {required: "<tpl> $langAMFillInCompositor </tpl>"}
					},
					submitHandler: function() {
						$('#' +  myform).ajaxSubmit({ beforeSubmit:function(){showLoading(showSaveText);},success: addAttr, type:'post', dataType:'json', resetForm: true});
					}
				});
				//return false;
			});
		}



	});
}

//删除属性
function delResponse(responseText,statusText){
	$.blockUI("<h1>" + responseText.message + "</h1>" );
	getAttribute('attribute.manage.php?action=ajax_show&pcid=' + pcid,1);
	//$.unblockUI();
}
/* 
* 删除商品分类属性
 */function delAtt(){


	var del_aid = document.getElementsByName('txtAid');
	var array_aid = new Array();

	for(i=0;i<del_aid.length;i++){
		if(del_aid[i].checked==true){
			array_aid.push(del_aid[i].value);
		}
	}
	if (array_aid == ''){
		var msg="<tpl> $langAMSelectDel </tpl>";
		showMessage(msg,0);
	}else{
		$.blockUI(question, { width: '275px' });

		$('#yes').click(function() {
			$.ajax({
				success: delResponse,
				url: 'attribute.manage.php?action=del',
				type: 'post',
				dataType: 'json',
				data: 'txtAid=' + array_aid
			});
			return false;
		});
		$('#no').click($.unblockUI);

	}
	//alert(array_aid);

}
/* 
* 调用div对话窗口
* 管理属性内容
 */function manage_ac(aid)
{
	$.ajax({
		url: 'attribute_content.manage.php?action=list',
		type: 'post',
		dataType: 'html',
		data: 'aid=' + aid,
		error: function(){
			alert('something wrong');
		},
		success: function(html){

			document.getElementById('contentDIV').innerHTML=html;
			var showData = document.getElementById('contentDIV').innerHTML;
			ScreenConvert();DialogShow(showData,500,300,500,400);

		}

	});

	//PostRequest(window.location.protocol + "//" + window.location.host + "/ajax_Comm.aspx", PostData);
	//$('#contentDIV').html('123');
	//ScreenConvert();DialogShow("<div id=\"DialogLoading\">正在读取,请稍候...</div>",110,10,124,20);
}

/* 
* 添加属性内容
 */function add_ac()
{
	var uaid = document.getElementById('txtaddAid').value;
	var uaccontent = document.getElementById('txtaddACcontent').value;
	var uacorder = document.getElementById('txtaddACorder').value;
	var uaname = document.getElementById('txtaddAname').value;
	//alert(uaccontent);
	$.ajax({
		url: 'attribute_content.manage.php?action=add',
		type: 'post',
		dataType: 'html',
		data: 'accontent=' + uaccontent +'&acorder=' + uacorder + '&aid=' + uaid,
		error: function(){
			alert('something wrong');
		},
		success: function(){
			//alert(msg);
			manage_ac(uaid);
		}
	});
}

/* 
* 编辑属性内容
 */function update_ac(acid)
{
	var uaid = document.getElementById('txtaddAid').value;
	var uaccontent = document.getElementById('txtupdateACcontent' + acid).value;
	var uacorder = document.getElementById('txtupdateACorder' + acid).value;
	var uaname = document.getElementById('txtaddAname').value;
	//alert(uaccontent);
	$.ajax({
		url: 'attribute_content.manage.php?action=update',
		type: 'post',
		dataType: 'html',
		data: 'accontent=' + uaccontent +'&acorder=' + uacorder + '&acid=' + acid,
		error: function(){
			alert('something wrong');
		},
		success: function(){
			//alert(msg);
			alert('<tpl> $langAMSaveOk </tpl>');
			manage_ac(uaid);
		}
	});
}

/* 
* 删除属性内容
 */function del_ac()
{
	var uaid = document.getElementById('txtaddAid').value;
	var uaname = document.getElementById('txtaddAname').value;
	var delacid = document.getElementsByName('txtupdateAcid');
	var array_aid = new Array();
	for(i=0;i<delacid.length;i++){
		if(delacid[i].checked==true){
			array_aid.push(delacid[i].value);
		}
	}
	if(array_aid == ''){
		alert('<tpl> $langAMPleaseSelectDel </tpl>');
		return false;
	}
	$.ajax({
		url: 'attribute_content.manage.php',
		type: 'post',
		dataType: 'html',
		data: 'action=del&acid='+array_aid,
		error: function(){
			alert('something wrong');
		},
		success: function(){
			//alert(msg);
			manage_ac(uaid);
		}
	});
}

//复制某一类别中所有属性
function copy_all_ac(){
	var aid = document.getElementsByName('txtAid');
	var array_aid = new Array();

	for(i=0;i<aid.length;i++){
		if(aid[i].checked==true){
			array_aid.push(aid[i].value);
		}
	}
	if (array_aid == ''){
		var msg="<tpl> $errACopySelPcClassIsWrong </tpl>";
		showMessage(msg,0);
	}else{
		$.ajax({
			url: 'attribute.manage.php',
			type: 'post',
			dataType: 'html',
			data: 'action=sel_copy_pcclass',
			error: function(){
				alert('something wrong');
			},
			success: function(html){
				//显示遮罩
				ScreenConvert();DialogShow(html,500,300,500,380);
				//给action 赋值
				$('#copy_form input[@id=action]').val('copy_all');
				//给属性id 赋值
				$('#copy_form input[@id=copy_a_id]').val(array_aid);
			}
		});
	}
	return false;
}

//提交属性复制表单
function copy_form_submit(){
	var str="";
	//右侧下拉菜单中的值拼成字符串
	$("#pclass_right_select").find("option").each(function(){
		str += this.value+',';
	});
	//验证右侧是否有值
	if(str == ""){
		alert('<tpl> $errACopySelPcClassIsWrong </tpl>');return false;
	}
	//
	$("#to_id").val(str);
	//取表单参数
	var queryString=$("#copy_form").formSerialize();
	$.ajax({
		success: function(msg){showMessage(msg.message,msg.type);DialogHide();$('#copyDIV').empty();},
		url: 'attribute.manage.php',
		type: 'post',
		dataType: 'json',
		data: queryString
	});
	return false;
}
</script>
